﻿# CMakeList.txt: vcpkg_integrate_test 的 CMake 项目，在此处包括源代码并定义
# 项目特定的逻辑。
#

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 判断操作系统是否为 Windows
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
    message(status "====================Detected Windows operating system")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    message(status "====================Detected Linux operating system")
else()
    
     message(status "====================Unknown operating system")
endif()


if(WIN32)
 message(status "====================Detected Windows operating system====================")
# 将源代码添加到此项目的可执行文件。
find_package(libevent CONFIG REQUIRED)
find_package(hiredis CONFIG REQUIRED)
#find_package(unofficial-evpp CONFIG REQUIRED)
# 查找 posix 线程库 pthreads 库
find_package(Threads REQUIRED)
else()

message(status "====================Detected Linux operating system====================")
# 将源代码添加到此项目的可执行文件。
find_package(libevent CONFIG REQUIRED)
find_package(hiredis CONFIG REQUIRED)
#find_package(unofficial-evpp CONFIG REQUIRED)
# 查找 pthreads 库
find_package(Threads REQUIRED)
#find_package(spdlog CONFIG REQUIRED)
endif()
file(GLOB common_utils_src "./utils/bytes_utils.h")
file(GLOB common_base64_src "./compositions/base64/Base64.h")
file(GLOB http_dispacher_src ./http_dispacher/*.cpp ./http_dispacher/*.h ./http_dispacher/*/*.h ./http_dispacher/*/*.cpp)
add_executable(http_dispacher "${http_dispacher_src}")

#libevent tcp app
file(GLOB libevent_tcp_apps_src ./tcp_apps/*.h ./tcp_apps/*.cpp)
add_executable(libevent_tcp_apps ${libevent_tcp_apps_src} ${common_utils_src})

#libevent pack server app
file(GLOB libevent_tcp_apps_packing_src ./tcp_apps_packing/*.h ./tcp_apps_packing/tcp_server.cpp ./tcp_apps/msg/*.h)
add_executable(libevent_tcp_packing_apps ${libevent_tcp_apps_packing_src} ${common_utils_src})
#libevent pack client app
file(GLOB libevent_tcp_client_apps_packing_src ./tcp_apps_packing/*.h ./tcp_apps_packing/tcp_client.cpp ./tcp_apps/msg/*.h)
add_executable(libevent_tcp_client_apps_packing ${libevent_tcp_client_apps_packing_src} ${common_utils_src})


file(GLOB JSONCPP_SRC ${CMAKE_CURRENT_SOURCE_DIR}/plugins/jsoncpp1.9.0/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/plugins/jsoncpp1.9.0/*.h)
file(GLOB COMPOSITION_PUBSUB ./compositions/*.h ./compositions/*.cpp ./compositions/messages/*.h  )
file(GLOB concurrents_thread_switch_src ./concurrents/thread_switch_main.h ./concurrents/thread_switch_main.cpp)
file(GLOB concurrents_thread_switch_simple_src ./concurrents/thread_switch_simple_main.h ./concurrents/thread_switch_simple_main.cpp)
file(GLOB BASE_64 ./compositions/base64/*.h compositions/base64/*.cpp )
file(GLOB RAPIDJSON_SRC ./plugins/rapidjson/*.h ./plugins/rapidjson/error/*.h ./plugins/rapidjson/internal/*.h ./plugins/rapidjson/msinttypes/*.h)
file(GLOB_RECURSE SUB_DISPACHER_SRC "sub_dispacher/*.cpp" "sub_dispacher/*.h")
add_executable(rapidjson_test "rapidjson_test/rapidjson_test.cpp" "rapidjson_test/archiver.h" "rapidjson_test/archiver.cpp" ${RAPIDJSON_SRC})
add_executable(concurrents_thread_switch ${concurrents_thread_switch_src})
add_executable(concurrents_thread_switch_simple ${concurrents_thread_switch_simple_src})
add_executable(libevent_http_redis_threadpool "libevent_http_redis_threadpool.cpp")
add_executable(libevent_http "libevent_http.cpp")
add_executable(libevent_threadpoll "libevent_threadpoll.cpp")
add_executable (test_subscribe "plugins/rediss/test_subscribe.cpp" "plugins/rediss/test_subscribe.h" ${common_utils_src} ${common_base64_src})
add_executable (test_publish "plugins/rediss/test_publish.h" "plugins/rediss/test_publish.cpp" ${common_utils_src} ${common_base64_src})
add_executable (vcpkg_integrate_test_libevent_server "LibeventTcpServer.cpp")
add_executable (vcpkg_integrate_test_libevent_tcpclient "LibeventTcpClient.cpp")
add_executable (vcpkg_integrate_test_unofficialEvppTest "unofficialEvppTest.cpp")
add_executable (test_cross_platform "test_cross_platform.cpp")
add_executable(test_windows_semaphore "test_windows_semaphore.cpp")
add_executable(redis_subscriber "redis_subscriber.h" "redis_subscriber.cpp" "redis_subscriber_main.cpp")
add_executable(redis_publisher "redis_publisher.h" "redis_publisher.cpp" "redis_publisher_main.cpp")
#set("EVENTLIB_LIBRARIES" D:/soft/vcpkg2/installed/x64-windows/lib/event.lib)
#set("EVENTLIB_LIBRARIES2" D:/soft/vcpkg2/buildtrees/libevent/x64-windows-rel/lib/event.lib)
#set("EVENTLIB_LIBRARIES3" D:/soft/vcpkg2/packages/libevent_x64-windows/lib/event.lib)

target_link_libraries(libevent_tcp_apps PRIVATE spdlog libevent::core libevent::extra)
target_link_libraries(libevent_tcp_packing_apps PRIVATE spdlog libevent::core libevent::extra)
target_link_libraries(libevent_tcp_client_apps_packing PRIVATE spdlog libevent::core libevent::extra)


target_link_libraries(concurrents_thread_switch PRIVATE spdlog)
target_link_libraries(concurrents_thread_switch_simple PRIVATE spdlog)
add_executable(compositions_pub "compositions/test/com_pub.cpp" ${JSONCPP_SRC} ${COMPOSITION_PUBSUB} ${BASE_64})
add_executable(compositions_sub "compositions/test/com_sub.cpp" ${JSONCPP_SRC} ${COMPOSITION_PUBSUB} ${BASE_64})

#target_link_libraries(test_cross_platform PRIVATE Threads::Threads)
target_link_libraries(http_dispacher PRIVATE hiredis::hiredis libevent::core libevent::extra)
target_link_libraries(libevent_http_redis_threadpool PRIVATE hiredis::hiredis libevent::core libevent::extra)

target_link_libraries(libevent_http PRIVATE hiredis::hiredis libevent::core libevent::extra)
target_link_libraries(libevent_threadpoll PRIVATE hiredis::hiredis libevent::core libevent::extra)
target_link_libraries(redis_publisher PRIVATE spdlog hiredis::hiredis libevent::core libevent::extra)
target_link_libraries(redis_subscriber PRIVATE spdlog hiredis::hiredis libevent::core libevent::extra)

target_link_libraries(test_subscribe PRIVATE spdlog hiredis::hiredis libevent::core libevent::extra)
target_link_libraries(test_publish PRIVATE spdlog hiredis::hiredis libevent::core libevent::extra)
target_link_libraries(vcpkg_integrate_test_libevent_server PRIVATE hiredis::hiredis libevent::core libevent::extra)
target_link_libraries(vcpkg_integrate_test_libevent_tcpclient PRIVATE hiredis::hiredis libevent::core libevent::extra)
 #target_link_libraries(vcpkg_integrate_test_unofficialEvppTest PRIVATE unofficial::evpp::evmc_static unofficial::evpp::evpp_static unofficial::evpp::evnsq_static unofficial::evpp::evpp_lite_static)
# if (CMAKE_VERSION VERSION_GREATER 3.12)
 #  set_property(TARGET vcpkg_integrate_test PROPERTY CXX_STANDARD 20)
# endif()
target_link_libraries(compositions_pub PRIVATE hiredis::hiredis libevent::core libevent::extra)
target_link_libraries(compositions_sub PRIVATE hiredis::hiredis libevent::core libevent::extra)
# TODO: 如有需要，请添加测试并安装目标。

#find_package(nlohmann_json CONFIG REQUIRED)
#target_link_libraries(main PRIVATE nlohmann_json::nlohmann_json)

find_package(cereal CONFIG REQUIRED)
add_executable(cereal_test_main "cereal_test_main.cpp")
target_link_libraries(cereal_test_main PRIVATE cereal::cereal)


add_subdirectory("report_on")

add_executable(sub_dispacher_test ${SUB_DISPACHER_SRC})
target_link_directories(sub_dispacher_test PRIVATE spdlog::spdlog)
set(CMAKE_INSTALL_LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
include_directories(report_on/include)
add_executable(report_on_test "pub_static_main.cpp" )
link_directories(${CMAKE_INSTALL_LIBDIR})
target_link_libraries(report_on_test report_on )

add_executable(basic_test ./basic/basic_main.cpp "basic/my_class.h")

#sqlpp11(必须手动安装sqlite3  vcpkg.exe install sqlite3)
# find_package(Sqlpp11 CONFIG REQUIRED)
#add_executable(sqlpp11_demo ./sqlpp11s/sqlpp11_main.cpp)
#target_link_libraries(sqlpp11_demo PRIVATE sqlpp11::sqlpp11 )

#grpc
#find_package(gRPC CONFIG REQUIRED)
#add_executable(grpc_server ./grpcs/grpc_server.cpp ./grpcs/messages.grpc.pb.cc ./grpcs/messages.grpc.pb.h)
#add_executable(grpc_client ./grpcs/grpc_client.cpp ./grpcs/messages.grpc.pb.cc ./grpcs/messages.grpc.pb.h)
#target_link_libraries(grpc_server PRIVATE gRPC::grpc++)
#target_link_libraries(grpc_client PRIVATE gRPC::grpc++)

add_subdirectory("libmysql")
add_subdirectory("deserialize_test")
add_subdirectory("grpcs")